/*
 * @Author: your name
 * @Date: 2022-03-10 21:50:19
 * @LastEditTime: 2022-04-06 16:30:37
 * @LastEditors: Please set LastEditors
 * @Description: 侧边栏菜单
 * @FilePath: \blog-system-front\src\Containers\CutomMenu.js
 */
import { Menu } from "antd";
import { Link } from "react-router-dom";
import { routerConfig } from "../routers/router";
import { openTab } from "../util/menTab";
const { SubMenu } = Menu;

const CoustomMenu = () => {
  const renderSumMenu = () => {
    return routerConfig.map((d) => {
      return (
        <SubMenu key={d.key} title={d.name}>
          {d.routes.map((item, index) => {
            return (
              <Menu.Item
                key={item.path}
                onClick={() => {
                  openTab({
                    ...item,
                    key:
                      item.path === "/article/write/:id"
                        ? "/article/write/new"
                        : item.path,
                    path:
                      item.path === "/article/write/:id"
                        ? "/article/write/new"
                        : item.path,
                  });
                }}
              >
                <Link
                  to={
                    item.path === "/article/write/:id"
                      ? "/article/write/new"
                      : item.path
                  }
                >
                  {item.name}
                </Link>
              </Menu.Item>
            );
          })}
        </SubMenu>
      );
    });
  };
  return (
    <Menu
      mode="inline"
      theme="dark"
      style={{ marginTop: 10, width: "100%" }}
      defaultOpenKeys={["article", "user"]}
    >
      {renderSumMenu()}
    </Menu>
  );
};
export default CoustomMenu;
